package com.treasure.common.utils;

import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;

import java.util.UUID;

/**
 * @author sunhongmin
 * @date 2023/11/11 11:07
 * @description
 */
@UtilityClass
public class RandomIdGenerator {

    /**
     * 企业ID
     */
    public static String corpId() {
        // atc+雪花ID取MD5
        return "atc" + MD5Utils.md5(SnowFlakeId.nextId());
    }

    /**
     * appKey
     */
    public static String appKey() {
        return "ak" + traceId();
    }

    /**
     * accountToken
     */
    public static String accountToken() {
        // atc+雪花ID取MD5
        return "sk" + MD5Utils.md5(SnowFlakeId.nextId());
    }

    /**
     * UserId
     */
    public static String userId(String corpId) {
        if (StringUtils.isNotBlank(corpId)) {
            String corpSubId = corpId.substring(corpId.length() - 6);
            return "user" + corpSubId + traceId();
        }

        return "user" + "undefined" + traceId();
    }

    /**
     * traceId
     */
    public static String traceId() {
        UUID id = UUID.randomUUID();
        String[] ids = id.toString().split("-");
        return ids[0] + ids[1];
    }


    public static void main(String[] args) {
        System.out.println(traceId());
        System.out.println(corpId());
        System.out.println(appKey());
        System.out.println(accountToken());
    }

}
